选择使用 git archive 还是 git bundle 取决于您是交付原始源代码,还是可移植的仓库历史记录。
1. 元数据包含与排除
主要的技术差异在于对 .git 目录 (内部对象) 的处理方式。 Git 归档 会主动丢弃这些内部元数据,以生成轻量级、"干净" 的文件结构。相反地, Git 打包 则保留了完整的对象图谱,实际上将该文件变成一个可移植的 源远程 (内部对象) 的处理方式。
2. 策略矩阵
| 特性 | Git 归档 | Git 打包 |
|---|---|---|
| 包含 .git 目录? | 否 | 是 |
| 提交历史 | 无 | 完整 |
| 用途 | 部署 | 传输 |
| 格式 | .zip / .tar | 二进制 |
3. 状态持久性
当目标为 主分支 (内部对象),归档是一个静态快照。而打包能保持 主分支 (quick_reference), allowing the recipient to perform git log 以及增量更新。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
Which command is most appropriate for sending source code to a client who does not use Git?
git bundle
git archive
git push --force
git commit -m
✅ Correct!
Git archive creates standard ZIP or TAR files that do not require Git to open or use.❌ Incorrect
Git bundle creates a binary file that requires Git for reconstruction.QUESTION 2
What happens to the
.git directory when running git archive?It is compressed into a .git.zip file.
It is renamed to .metadata.
It is intentionally excluded from the resulting file.
It is moved to the root folder.
✅ Correct!
Archiving aims for a 'clean' snapshot, so all internal Git metadata is stripped.❌ Incorrect
The .git directory is omitted to ensure the archive contains only the source code.QUESTION 3
A
git bundle acts most like which of the following?A text-only patch file.
A file-based origin remote.
A temporary stash.
A Git hook script.
✅ Correct!
Because it contains the object database, you can clone and fetch from a bundle file as if it were a server.❌ Incorrect
A bundle is much more than a patch; it is a serialized version of the repository's history.QUESTION 4
Which file format does
git bundle produce?Plain Text (.txt)
Binary (.bundle)
Compressed Folder (.zip)
Markdown (.md)
✅ Correct!
Bundles are binary representations of the Git object database.❌ Incorrect
While archives use ZIP/TAR, bundles use a proprietary Git binary format.QUESTION 5
Why would a developer in an air-gapped facility prefer a bundle over an archive?
Bundles are smaller in size.
Bundles allow them to access the full commit history offline.
Archives are incompatible with Linux.
Bundles automatically encrypt the source code.
✅ Correct!
Bundles provide the 'Repository Portability' needed to perform operations like 'git log' without a network.❌ Incorrect
Archives only provide a flat snapshot, which prevents seeing previous commits or branches.Case Study: The Secure Research Lab
Managing Code in High-Security Environments
You are a software lead delivering a project to a developer in a 'sneakernet' environment (no internet). They need to be able to see the development history of the master branch and contribute new commits back later.
Q
1. Which command should you use to package the repository for the developer?
Solution:
You should use
You should use
git bundle create repo.bundle master. This ensures the master branch (internal_object) and its history are encapsulated in a single file.Q
2. How will the receiving developer initialize their local workspace using your file?
Solution:
They will use
They will use
git clone repo.bundle -b master. This treats the bundle as an offline remote and reconstructs the full repository history.